package com.blog.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.dao.CommentMapper;
import com.blog.model.Comment;
import com.blog.service.interfaces.ICommentService;
@Service("commentService")
public class CommentService implements ICommentService {
	@Autowired
	CommentMapper commentMapper;
	
	public int addComment(Comment comment){
		return commentMapper.insert(comment);
	}
	
	public List<Comment> getCommentByArticleid(int link_articleId){
		return commentMapper.selectByArticleid(link_articleId);
	}
 
	public List<Comment> getCommentByCommentAuthor(int link_articleId, int link_reply_comment_id){
		return commentMapper.selectByCommentAuthor(link_articleId,link_reply_comment_id);
	}
	
	public HashMap<Comment,List<Comment>> getCommentAndReplyByArticleid(int link_articleId){
		LinkedHashMap<Comment,List<Comment>> allComment = new LinkedHashMap<Comment,List<Comment>>();
		List<Comment> mainComments=commentMapper.selectByArticleid(link_articleId);
		for(Comment mainComment:mainComments){
			allComment.put(mainComment,commentMapper.selectByCommentAuthor(link_articleId,mainComment.getComment_id()));
		}
		return allComment;
		
	}
}
